import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_api_path.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/models/xindong_notice_class.dart';
import 'package:xindong/routes/common/xindong_web_html_yemian.dart';
import 'package:xindong/routes/tab_chats/controller/xindong_notice_vm.dart';
import 'package:xindong/routes/tab_chats/view/xindong_notice_message_cell.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/container/xindong_empty_container.dart';
import 'package:xindong/widgets/container/xindong_getx_builder_container.dart';

class XinDongNoticeYeMian extends StatelessWidget {
  const XinDongNoticeYeMian({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(XinDongNoticeVM());
    return Scaffold(
      appBar: XinDongAppBar("系统通知"),
      body: XinDongGetBuilder<XinDongNoticeVM>(builder: (viewClass) {
        return XinDongRefreshContainer(
          viewClass: viewClass,
          child: XinDongEmptyContainer(
            dataList: viewClass.dataList,
            emptyTips: "暂无最新消息～",
            child: ListView.separated(
              controller: viewClass.scrollController,
              itemCount: viewClass.dataList?.length ?? 0,
              itemBuilder: (BuildContext context, int index) {
                XinDongNoticeClass model = viewClass.dataList![index];
                return XinDongNoticeMessageCell(
                  model: model,
                  onTap: () {
                    XinDongPageSingleton.instance
                        .pushYeMian(XinDongWebHtmlYeMian(title: model.type_text, html: model.context));
                    XinDongNetworking.instance.request(XinDongApi.messageDetail,
                        method: XinDongHttpMethod.post, parameters: {"id": model.id});
                  },
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return const SizedBox(height: 1.0);
              },
            ),
          ),
        );
      }),
    );
  }
}
